<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="com.sundy.core.*"%>
<%@ page import="com.sundy.service.*"%>
<%@ page import="com.sundy.tools.*"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	Context context = Utility.obtainContext(request);
	List<TeacherTbl> list = (List<TeacherTbl>) request
			.getAttribute("lst");
	List<DescriptTbl> list2 = (List<DescriptTbl>) request
			.getAttribute("lst2");
	request.setAttribute("title", "管理");
	List<String> xlss = (List<String>) request.getAttribute("xls");
	List<SubjectTbl> sublist = (List<SubjectTbl>) request
			.getAttribute("sublist");
%>

<jsp:include page="/head.jsp" flush="true"></jsp:include>
<script type="text/javascript">
<!--
function deleteconfirm() {
	return confirm("您真的要删除该用户吗？");
}

function deletefile(){
   return confirm("您真的要删除该文件吗？");
}

function check3() {
  var pass1 = $.trim($("#pass1").val());
  var pass2 = $.trim($("#pass2").val());
  if (pass1 == "" || pass2 == "") {
    alert("请输入新密码");
    return false;
  }
  if (pass1 != pass2) {
    alert("您两次输入的密码不一致，请重新输入");
    return false;
  }
  return true;
}

function exportscore(idstr) {
  $.get("<%=request.getContextPath()%>/admin/export?id=" + idstr, function (data) {
  		alert($.trim(data));
  });
  alert("系统正在生成Excel格式的导出文件，请片刻后到\"登分表下载\"区下载，所需时间与服务器负载有关。");
}

$(function() {
	$("#Tabs").tabs();
});
-->
</script>
<div id="mgr" class="left">
	<div style="height: 30px;">
		&nbsp;
	</div>
	<div id="Tabs">
		<ul>
			<li>
				<a href="#score-list">登分表列表</a>
			</li>
			<li>
				<a href="#tabs-user">用户管理</a>
			</li>
			<li>
				<a href="#tabs-mapping">科目设置</a>
			</li>
			<li>
				<a href="#tabs-score">管理登分表</a>
			</li>
			<li>
				<a href="#tabs-export">登分表下载列表</a>
			</li>
			<li>
				<a href="#tabs-subjectmax">科目最高分设置</a>
			</li>
			<li>
				<a href="#tabs-subject">科目操作</a>
			</li>
			<li>
				<a href="#set-pass">修改密码</a>
			</li>
		</ul>
		<div id="score-list">
			<table style="width: 100%; border: 1px solid #cccccc;">
				<tr>
					<td>
						<%
							List<String> list3 = WebUtility.getTeacherSubjects(context
									.getCurrentUser());
							for (String str : list3) {
								String[] strs = str.split("\\|");
						%>
						<a href="<%=path%>/mgr/score?id=<%=strs[1]%>&sub=<%=strs[2] %>"><%=strs[0]%></a>
						<br />
						<%
							}
						%>
					</td>
				</tr>
			</table>
		</div>
		<div id="tabs-user">
			<table style="width: 100%; border: 1px solid #cccccc;">
				<tr>
					<td width="30%">
						用户名
					</td>
					<td width="40%">
						角色
					</td>
					<td>
						&nbsp;
					</td>
					<td>
						&nbsp;
					</td>
				</tr>
				<%
					for (TeacherTbl usr : list) {
				%>
				<tr>
					<form action="<%=path%>/admin/usrmgr" method="post">
						<td>
							<%=usr.getName()%>
						</td>
						<td width="15%">
							<%=WebUtility.outRight(usr)%>
						</td>
						<td>
							<input type="hidden" name="action" value="update" />
							<input type="hidden" name="id" value="<%=usr.getId()%>" />
							<input type="submit" value="更新" />
						</td>
					</form>
					<form action="<%=path%>/admin/usrmgr" method="post"
						onsubmit="return deleteconfirm();">
						<td>
							<input type="hidden" name="action" value="delete" />
							<input type="hidden" name="id" value="<%=usr.getId()%>" />
							<input type="submit" value="删除" />
						</td>
					</form>
				</tr>
				<%
					}
				%>
			</table>
			<script type="text/javascript">
function descdelete() {
	return confirm("您真的要删除该登分表吗?");
}
function check() {
	if ($.trim($("#name").val()) == "") {
		alert("请输入用户名");
		return false;
	}
	if ($.trim($("#password").val()) == "") {
		alert("请输入密码");
		return false;
	}
	return true;
}
</script>
			<hr size="1" />
			<form action="<%=path%>/admin/adduser" method="post"
				onsubmit="return check();">
				<table>
					<tr>
						<td colspan="2">
							添加用户
						</td>
					</tr>
					<tr>
						<td>
							用户名
						</td>
						<td>
							<input class="userinfo" type="text" id="name" name="name"
								size="20" />
						</td>
					</tr>
					<tr>
						<td>
							密&nbsp;码
						</td>
						<td>
							<input class="userinfo" type="password" id="password"
								name="password" size="20" />
						</td>
					</tr>
					<tr>
						<td>
							&nbsp;
						</td>
						<td>
							<input type="submit" value="增加" />
							&nbsp;
							<input type="reset" value="重置" />
						</td>
					</tr>
				</table>
			</form>
		</div>
		<div id="tabs-mapping">
			<table style="width: 100%; border: 1px solid #cccccc;">
				<tr>
					<td width="25%">
						用户名
					</td>
					<td width="60%">
						登分科目
					</td>
					<td>
						&nbsp;
					</td>
					<td>
						&nbsp;
					</td>
				</tr>
				<%
					for (TeacherTbl usr : list) {
				%>
				<tr>
					<form action="<%=path%>/admin/usrmgr" method="post">
						<td>
							<%=usr.getName()%>
						</td>
						<td width="40%">
							<%=WebUtility.outMapping(usr)%>
						</td>
						<td>
							<input type="hidden" name="action" value="mapping" />
							<input type="hidden" name="id" value="<%=usr.getId()%>" />
							<input type="submit" value="更新" />
						</td>
					</form>
				</tr>
				<%
					}
				%>
			</table>
		</div>
		<div id="tabs-score">
			<table style="width: 100%; border: 1px solid #cccccc;">
				<tr>
					<td width="40%">
						登分表名称
					</td>
					<td width="20%">
						状态
					</td>
					<td>
						&nbsp;
					</td>
					<td>
						&nbsp;
					</td>
				</tr>
				<%
					for (DescriptTbl dt : list2) {
				%>
				<tr>
					<form action="<%=path%>/admin/usrmgr" method="post">
						<td>
							<a
								href="<%=request.getContextPath()%>/admin/view?id=<%=dt.getId()%>"><%=dt.getCaption()%></a>
						</td>
						<td>
							<input type="hidden" name="action" value="updatedesc" />
							<input type="hidden" name="id" value="<%=dt.getId()%>" />
							<%=WebUtility.outDescrpt(dt)%>
						</td>
						<td>
							<input type="submit" value="更新" />
						</td>
					</form>
					<form action="<%=path%>/admin/usrmgr" method="post"
						onsubmit="return descdelete();">
						<td>
							<input type="hidden" name="action" value="descdel" />
							<input type="hidden" name="id" value="<%=dt.getId()%>" />
							<input type="submit" value="删除" />
							&nbsp;
							<input type="button" value="导出登分表"
								onclick="exportscore('<%=dt.getId()%>')" />

						</td>
					</form>
				</tr>
				<%
					}
				%>
			</table>
			<div style="float: right;">
				<form action="<%=request.getContextPath()%>/model.xls" method="get">
					<input type="submit" value="下载标准的登分表模板" />
				</form>
			</div>
			<br />
			<script type="text/javascript">
function check2() {
	if ($.trim($("#score").val()) == "") {
		alert("没有选择文件");
		return false;
	}
	if ($.trim($("#scname").val()) == "") {
		alert("没有填写登分表名称");
		return false;
	}
	return true;
}
</script>
			<form enctype="multipart/form-data" action="<%=path%>/admin/addscore"
				method="post" onsubmit="return check2();">
				<table style="width: 100%; border: 1px solid #cccccc;">
					<tr>
						<td colspan="2">
							新增登分表
						</td>
					</tr>
					<tr>
						<td>
							登分表名称
						</td>
						<td>
							<input class="custominput" name="scname" id="scname" type="text"
								size="40" />
						</td>
					</tr>
					<tr>
						<td>
							登分表类型
						</td>
						<td>
							<select name="subtype">
								<option value="0" selected="selected">
									理科
								</option>
								<option value="1">
									文科
								</option>
								<option value="2">
									综合(不分文理)
								</option>
							</select>
						</td>
					</tr>
					<tr>
						<td width="20%">
							登分表路径
						</td>
						<td>
							<input type="file" id="score" name="score" />
						</td>
					</tr>
					<tr>
						<td width="20%">
							&nbsp;
						</td>
						<td>
							<input type="submit" value="提交" />
							&nbsp;
							<input type="reset" value="重置" />
						</td>
					</tr>
				</table>
			</form>
		</div>
		<div id="tabs-export">
			<table style="width: 100%; border: 1px solid #cccccc;">
				<%
					for (String file_name : xlss) {
				%>
				<tr>
					<td align="left">
						<a
							href="<%=request.getContextPath()%>/admin/file?name=<%=file_name%>"><%=file_name%></a>
					</td>
					<td>
						<form action="<%=request.getContextPath()%>/admin/usrmgr"
							method="post" onsubmit="return deletefile();">
							<input type="hidden" name="action" value="deletefile" />
							<input type="hidden" name="file" value="<%=file_name%>" />
							<input type="submit" value="删除" />
						</form>
					</td>
				</tr>
				<%
					}
				%>
			</table>
		</div>
		<div id="set-pass">
			<table style="width: 100%; border: 1px solid #cccccc;">
				<form action="<%=request.getContextPath()%>/admin/usrmgr"
					method="post" onsubmit="return check3();">
					<input type="hidden" name="action" value="passmodify" />
					<tr>
						<td align="right">
							新密码
						</td>
						<td>
							&nbsp;
							<input class="userinfo" id="pass1" name="pass1" type="password" />
						</td>
					</tr>
					<tr>
						<td align="right">
							确认新密码
						</td>
						<td>
							&nbsp;
							<input class="userinfo" id="pass2" name="pass2" type="password" />
						</td>
					</tr>
					<tr>
						<td>
							&nbsp;
						</td>
						<td>
							&nbsp;
							<input type="submit" value="修改" />
							&nbsp;
							<input type="reset" value="重置" />
						</td>
					</tr>
				</form>
			</table>
		</div>
		<div id="tabs-subjectmax">
			<table style="width: 100%; border: 1px solid #cccccc;">
				<tr>
					<td width="40%">
						科目
					</td>
					<td width="25%">
						最高分数
					</td>
					<td width="35%">
						&nbsp;
					</td>
				</tr>
				<%
					for (SubjectTbl sub : sublist) {
				%>
				<tr>
					<form action="<%=path%>/admin/usrmgr" method="post">
						<td>
							<%=sub.getCaption()%>
						</td>
						<td width="25%">
							<input type="text" name="max"
								value="<%=WebUtility.getSubjectMax(sub.getId())%>" />
						</td>
						<td width="15%">
							<input type="hidden" name="id" value="<%=sub.getId()%>" />
							<input type="hidden" name="action" value="scoremax" />
							<input type="submit" value="更新" />
						</td>
					</form>
				</tr>
				<%
					}
				%>
			</table>
		</div>
		<script type="text/javascript">
function delsubj(subname) {
	return confirm("您真的要删除科目: " + subname + "？");
}
</script>
		<div id="tabs-subject">
			<table style="width: 100%; border: 1px solid #cccccc;">
				<tr>
					<td width="60%">
						科目
					</td>
					<td width="35%">
						&nbsp;
					</td>
				</tr>
				<%
					for (SubjectTbl sub : sublist) {
				%>
				<tr>
					<form action="<%=path%>/admin/usrmgr" method="post"
						onsubmit="return delsubj('<%=sub.getCaption()%>');">
						<td>
							<%=sub.getCaption()%>
						</td>
						<td>
							<input type="hidden" name="id" value="<%=sub.getId()%>" />
							<input type="hidden" name="action" value="subdel" />
							<input type="submit" value="删除" />
						</td>
					</form>
				</tr>
				<%
					}
				%>
			</table>
		</div>
	</div>
</div>
<jsp:include page="footer.jsp"></jsp:include>
